package com.rightsidetech.http.controller.agentAdmin.store;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.SysStoreIdReq;
import com.rightsidetech.system.dtos.request.SysStoreStorkReplenishInfoReq;
import com.rightsidetech.system.dtos.request.store.SysAgentStorkPageReq;
import com.rightsidetech.system.dtos.request.store.SysAgentStorkReplenishReq;
import com.rightsidetech.system.dtos.response.SysStoreStorkInfoResp;
import com.rightsidetech.system.dtos.response.SysStoreStorkReplenishInfoResp;
import com.rightsidetech.system.dtos.response.store.SysAgentStorkPageResp;
import com.rightsidetech.system.dtos.response.store.SysAgentStorkReplenishResp;
import com.rightsidetech.system.service.SysStoreStorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

/**
 * @Author: yhr
 * @Date: 2021-12-30 16:24
 */
@RestController
@RequestMapping("/agentAdmin/store_stork")
@ShenyuSpringMvcClient(path = "/agentAdmin/store_stork/**")
@Api(tags = "门店库存")
public class SysAgentStorkController extends BaseController {
    @Resource
    private SysStoreStorkService sysStoreStorkService;

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/page")
    @ApiOperation("库存列表")
    public ResponseData<PageInfo<SysAgentStorkPageResp>> page(SysAgentStorkPageReq page) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(page);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreStorkService.pageAgent(page,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/storkInfo")
    @ApiOperation("库存详情列表")
    public ResponseData<PageInfo<SysStoreStorkInfoResp>> storkInfo(SysStoreIdReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreStorkService.selectAgentReplenishInfo(req,loginInfoId);
    }
    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/replenish")
    @ApiOperation("补货记录列表")
    public ResponseData<PageInfo<SysAgentStorkReplenishResp>> replenish(SysAgentStorkReplenishReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreStorkService.replenishAgentPage(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/replenishInfo")
    @ApiOperation("补货详情列表")
    public ResponseData<PageInfo<SysStoreStorkReplenishInfoResp>> replenishInfo(SysStoreStorkReplenishInfoReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreStorkService.replenishAgentInfo(req,loginInfoId);
    }

}
